from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-30 14:02:21.436292
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 30, Jun, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6442
Nobs: 703.000 HQIC: -50.0020
Log likelihood: 8767.31 FPE: 1.53647e-22
AIC: -50.2274 Det(Omega_mle): 1.35306e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297488 0.057676 5.158 0.000
L1.Burgenland 0.107408 0.037886 2.835 0.005
L1.Kärnten -0.109562 0.020057 -5.463 0.000
L1.Niederösterreich 0.211430 0.079123 2.672 0.008
L1.Oberösterreich 0.105105 0.077542 1.355 0.175
L1.Salzburg 0.256483 0.040502 6.333 0.000
L1.Steiermark 0.045237 0.052762 0.857 0.391
L1.Tirol 0.109410 0.042831 2.554 0.011
L1.Vorarlberg -0.058996 0.037159 -1.588 0.112
L1.Wien 0.041445 0.068648 0.604 0.546
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049902 0.120946 0.413 0.680
L1.Burgenland -0.034175 0.079446 -0.430 0.667
L1.Kärnten 0.041153 0.042058 0.978 0.328
L1.Niederösterreich -0.168536 0.165919 -1.016 0.310
L1.Oberösterreich 0.424510 0.162604 2.611 0.009
L1.Salzburg 0.289136 0.084930 3.404 0.001
L1.Steiermark 0.100968 0.110640 0.913 0.361
L1.Tirol 0.319088 0.089815 3.553 0.000
L1.Vorarlberg 0.028065 0.077921 0.360 0.719
L1.Wien -0.042750 0.143952 -0.297 0.766
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187154 0.029528 6.338 0.000
L1.Burgenland 0.090237 0.019396 4.652 0.000
L1.Kärnten -0.007968 0.010268 -0.776 0.438
L1.Niederösterreich 0.266624 0.040508 6.582 0.000
L1.Oberösterreich 0.135687 0.039699 3.418 0.001
L1.Salzburg 0.046444 0.020735 2.240 0.025
L1.Steiermark 0.020449 0.027012 0.757 0.449
L1.Tirol 0.091588 0.021928 4.177 0.000
L1.Vorarlberg 0.056226 0.019024 2.956 0.003
L1.Wien 0.114784 0.035145 3.266 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111906 0.030037 3.726 0.000
L1.Burgenland 0.045645 0.019730 2.313 0.021
L1.Kärnten -0.013777 0.010445 -1.319 0.187
L1.Niederösterreich 0.192403 0.041205 4.669 0.000
L1.Oberösterreich 0.301665 0.040382 7.470 0.000
L1.Salzburg 0.108215 0.021092 5.131 0.000
L1.Steiermark 0.105045 0.027477 3.823 0.000
L1.Tirol 0.103809 0.022305 4.654 0.000
L1.Vorarlberg 0.067458 0.019352 3.486 0.000
L1.Wien -0.023113 0.035750 -0.647 0.518
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134170 0.054821 2.447 0.014
L1.Burgenland -0.051499 0.036011 -1.430 0.153
L1.Kärnten -0.044370 0.019064 -2.327 0.020
L1.Niederösterreich 0.157131 0.075206 2.089 0.037
L1.Oberösterreich 0.139241 0.073703 1.889 0.059
L1.Salzburg 0.286609 0.038496 7.445 0.000
L1.Steiermark 0.047639 0.050150 0.950 0.342
L1.Tirol 0.166981 0.040710 4.102 0.000
L1.Vorarlberg 0.093065 0.035319 2.635 0.008
L1.Wien 0.073365 0.065249 1.124 0.261
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054609 0.043588 1.253 0.210
L1.Burgenland 0.037741 0.028632 1.318 0.187
L1.Kärnten 0.051092 0.015158 3.371 0.001
L1.Niederösterreich 0.217659 0.059796 3.640 0.000
L1.Oberösterreich 0.294624 0.058601 5.028 0.000
L1.Salzburg 0.047709 0.030608 1.559 0.119
L1.Steiermark 0.001734 0.039874 0.043 0.965
L1.Tirol 0.140582 0.032369 4.343 0.000
L1.Vorarlberg 0.073753 0.028082 2.626 0.009
L1.Wien 0.081410 0.051880 1.569 0.117
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175524 0.052139 3.366 0.001
L1.Burgenland -0.002331 0.034249 -0.068 0.946
L1.Kärnten -0.063002 0.018131 -3.475 0.001
L1.Niederösterreich -0.080801 0.071527 -1.130 0.259
L1.Oberösterreich 0.194008 0.070098 2.768 0.006
L1.Salzburg 0.056758 0.036613 1.550 0.121
L1.Steiermark 0.236534 0.047696 4.959 0.000
L1.Tirol 0.497556 0.038719 12.851 0.000
L1.Vorarlberg 0.044721 0.033592 1.331 0.183
L1.Wien -0.056450 0.062057 -0.910 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169403 0.059271 2.858 0.004
L1.Burgenland -0.012621 0.038934 -0.324 0.746
L1.Kärnten 0.063856 0.020611 3.098 0.002
L1.Niederösterreich 0.207284 0.081311 2.549 0.011
L1.Oberösterreich -0.078832 0.079687 -0.989 0.323
L1.Salzburg 0.213225 0.041622 5.123 0.000
L1.Steiermark 0.126521 0.054221 2.333 0.020
L1.Tirol 0.067054 0.044015 1.523 0.128
L1.Vorarlberg 0.119070 0.038187 3.118 0.002
L1.Wien 0.127432 0.070546 1.806 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363146 0.034327 10.579 0.000
L1.Burgenland 0.007528 0.022549 0.334 0.738
L1.Kärnten -0.023679 0.011937 -1.984 0.047
L1.Niederösterreich 0.215175 0.047092 4.569 0.000
L1.Oberösterreich 0.206694 0.046151 4.479 0.000
L1.Salzburg 0.043264 0.024105 1.795 0.073
L1.Steiermark -0.014827 0.031402 -0.472 0.637
L1.Tirol 0.105857 0.025491 4.153 0.000
L1.Vorarlberg 0.069507 0.022116 3.143 0.002
L1.Wien 0.029705 0.040857 0.727 0.467
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037590 0.136352 0.193976 0.155191 0.114781 0.101441 0.057976 0.218415
Kärnten 0.037590 1.000000 -0.015115 0.134214 0.055954 0.095385 0.435724 -0.053050 0.093382
Niederösterreich 0.136352 -0.015115 1.000000 0.335543 0.141605 0.294198 0.092372 0.177157 0.309297
Oberösterreich 0.193976 0.134214 0.335543 1.000000 0.226972 0.325083 0.176069 0.164352 0.265225
Salzburg 0.155191 0.055954 0.141605 0.226972 1.000000 0.137847 0.116460 0.138791 0.130422
Steiermark 0.114781 0.095385 0.294198 0.325083 0.137847 1.000000 0.145632 0.129350 0.073325
Tirol 0.101441 0.435724 0.092372 0.176069 0.116460 0.145632 1.000000 0.113040 0.141190
Vorarlberg 0.057976 -0.053050 0.177157 0.164352 0.138791 0.129350 0.113040 1.000000 0.005191
Wien 0.218415 0.093382 0.309297 0.265225 0.130422 0.073325 0.141190 0.005191 1.000000